<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Drag实现</title>
  <style>
    body {
      display: flex;
    }

    .left {
      width: 300px;
      height: 500px;
      border: 3px solid lightcoral;
      box-sizing: border-box;
    }

    .right {
      display: flex;
      flex-direction: column;
      margin-left: 30px;
    }

    .right div {
      width: 200px;
      height: 200px;
      background-color: lightblue;
      margin-bottom: 5px;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <!-- 
  元素需要设置draggable="true"开启拖动
  1.拖动时
  开始 dragstart
  进行中 drag
  结束 dragend

  2.进去区域
  进入时 dragenter
  进入后 dragover
  离开 dragleave
  放置 drop 
-->

  <div class="left"></div>
  <div class="right">
    <div id="box1" draggable="true">1</div>
    <div id="box2" draggable="true">2</div>
    <div id="box3" draggable="true">3</div>
  </div>

  <script>
    const empty = document.querySelector('.left')
    let name = ''
    document.addEventListener('dragstart', (e) => {
      console.log(e);
      e.target.style.border = "5px dashed red"
      name = e.target.innerText
    }, false)
    document.addEventListener("dragend", (e) => {
      e.target.style.border = "none"
      empty.style.border = "3px solid lightcoral"
    }, false)
    document.addEventListener("drag", (e) => {
      e.preventDefault();
      e.target.style.border = "5px dashed red"
      empty.style.border = "5px dashed red"
    }, false)
    empty.addEventListener("dragenter", (e) => {
      e.preventDefault();
      empty.innerText = name
    }, false)
    empty.addEventListener("dragover", (e) => {
      e.preventDefault();
    }, false)

    // const box1 = document.querySelector("#box1")
    // box1.addEventListener("dragenter", (e) => {
    //   e.preventDefault()
    // }, false)
    // box1.addEventListener("dragover", (e) => {
    //   e.preventDefault()
    // }, false)


  </script>

</body>

</html>